import java.io.ByteArrayInputStream;
import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;


public class ByteReaderTest {
	
	public static void main(String args[]) {

		int testSize = 1000;

		Model modelTmp = ModelFactory.createDefaultModel();
		String foo = "<http://dbpedia.org/resource/Framlingham> a <http://dbpedia.org/class/yago/MarketTownsInEngland> .";		
		StringBuffer buffer = new StringBuffer();
		for(int i=0;i<testSize;i++) {
			buffer.append(foo);
		}
		byte[] bytes1 = buffer.toString().getBytes();
		InputStream is1 = new ByteArrayInputStream(bytes1);
		modelTmp.read(is1, null, "TURTLE");
		
		Model model1 = modelTmp;
		Model model2 = modelTmp;
		
		long startTime = System.currentTimeMillis();
		for(int i=0;i<testSize;i++) {
			byte[] bytes = buffer.toString().getBytes();
			InputStream is = new ByteArrayInputStream(bytes);
			model1.read(is, null, "TURTLE");
		}
		long endTime = System.currentTimeMillis();
		System.out.println("Multiple Reads: " + (endTime-startTime) + "ms");
		
		//benchmark: only one big read
//		model = ModelFactory.createDefaultModel();
		
		startTime = System.currentTimeMillis();
		for(int i=0;i<testSize;i++) {
			buffer.append(foo);
		}
		byte[] bytes = buffer.toString().getBytes();
		InputStream is = new ByteArrayInputStream(bytes);
		model2.read(is, null, "TURTLE");
		endTime = System.currentTimeMillis();
		System.out.println("One read: " + (endTime-startTime) + "ms");
	}
}
